<?php include_once './application/views/sys_admin/common/header.php';  ?>
<div class=" definewidth m20">
		<form action="/sys_admin/site/zhs_sitelist/" method="get" name="form" id="form" class="form-inline definewidth m20">
  			上级分类：<select id="parent_id" name="parent_id">
			  			<option value="" <?php if (''==$pid) echo "selected='selected'";?>>全部</option>
	  				<?php foreach($site_array as $val){?>
	  				<option value="<?php echo $val['id'];?>" <?php if ($val['id']==$pid) echo "selected='selected'";?>><?php echo $val['title'];?></option>
	  				<?php }?>
	  				</select>
  			<button type="button" class="btn btn-primary"  onclick="this.form.submit();" >查询</button>
  			<button type="button" class="btn btn-success"  onclick="href('/sys_admin/site/add_view/');" >添加 类别</button>
  		</form>
		<table class="table table-bordered table-hover definewidth m10">
			 <thead>
			    <tr>
			        <th >编号</th>
					<th >分类名称</th>
					<th >分类nid</td>
					<th >分类排序</th>
					<th >操作</th>
			    </tr>
			   </thead>
			    <?php foreach($site_list as $key=>$site){?>
			  <tr id="row_<?php echo $site['id'];?>"  parentid="0" typeid="<?php echo $site['id'];?>" overstyle="on" >
				<td ><?php echo $site['id'];?></td>
				<td >
					<?php if($site['parent_id'] == 0 && $site['type_set'] == 0 && isset($site['category_list']) && is_array($site['category_list']) && count($site['category_list'])>0){?>
						<span id="row_type_<?php echo $site['id'];?>" class="typeson typeon" typeid="<?php echo $site['id'];?>" onclick="toggle_group(this)">&nbsp;</span>
					<?php }?>
					<?php echo $site['title'];?>
			  </td>
				<td ><?php echo $site['url'];?></td>
				<td ><?php echo $site['forder'];?></td>
				<td >
				<a href="/sys_admin/site/edit_view/<?php echo $site['id'];?>">编辑</a>
				<a href="javascript:if(confirm('确定删除站点？')){remove(<?php echo $site['id'];?>);}">删除</a>
				</td>
			  </tr>
			  <?php if(isset($site['category_list']) && is_array($site['category_list']) && count($site['category_list'])>0){?>
			  	<tbody id="parent_<?php echo $site['id'];?>" style="display:none;">
			  	<?php foreach($site['category_list'] as $k=>$v){?>
			  	<tr id="row_<?php echo $v['id'];?>" class="leve_2" parentid="<?php echo $site['id'];?>" typeid="<?php echo $v['id'];?>" overstyle="on" >
				  	<td ><?php echo $v['id'];?></td>
					<td>
						<?php if( $v['type_set'] == 0 && isset($v['second_list']) && is_array($v['second_list']) && count($v['second_list'])>0){?>
							<span id="row_type_sec$v['id'];?>" class="typeson typeon" typeid="<?php echo $v['id'];?>" onclick="sec_group(this)">&nbsp;</span>
						<?php }else{?>
						<span class="typeson">&nbsp;</span>
						<?php }?>
						<?php echo $v['title'];?>
				  </td>
					<td ><?php echo $v['url'];?></td>
					<td ><?php echo $v['forder'];?></td>
					<td >
						<a href="/sys_admin/site/edit_view/<?php echo $v['id'];?>">编辑</a>
						<a href="javascript:if(confirm('确定删除站点？')){remove(<?php echo $v['id'];?>);}">删除</a>
				  	</td>	
			  	</tr>
			  	<?php if(isset($v['second_list']) && is_array($v['second_list']) && count($v['second_list'])>0){?>
			  			
			  	<?php foreach($v['second_list'] as $sk=>$sv){?>
			  	
			  	<tr id="row_<?php echo $sv['id'];?>" class="leve_2" parentid="<?php echo $v['id'];?>" typeid="<?php echo $sv['id'];?>" overstyle="on" style="display:none;" >
				  	<td ><?php echo $sv['id'];?></td>
					<td>
						<span class="typeson">&nbsp;</span>
						<?php echo $sv['title'];?>
				  </td>
					<td ><?php echo $sv['url'];?></td>
					<td ><?php echo $sv['forder'];?></td>
					<td >
						<a href="/sys_admin/site/edit_view/<?php echo $sv['id'];?>">编辑</a>
						<a href="javascript:if(confirm('确定删除站点？')){remove(<?php echo $sv['id'];?>);}">删除</a>
				  	</td>	
			  	</tr>
			  	<?php }?>
			  	<?php }?>
			  	
			  		
			  	<?php }?>
			  	</tbody>
			  	
			  	<?php }?>
			  <?php }?>
			  	<tr>
			  	<td colspan="8"   class="page"><?php echo $this->pagination->create_links();?></td>
			  	</tr>
		</table>
</div>
<script  type="text/javascript">
function remove(id){
	$.ajax({
		type: "post",
		url: "/sys_admin/site/remove/",
		data: "id="+id,
		success: function(msg){
			$("#dialog" ).dialog();
			if(msg == 1){
				$("#msg").html("删除成功！");
				$("#row_"+id).hide();
			}else{
				$("#msg").html("删除失败，请联系管理员！");
			}
			setTimeout(function(){
				$("#dialog" ).dialog("close");
			},3000);
		},
		dataType: "text"
	});
}

function toggle_group(_this) {
	var typeid = $(_this).attr('typeid');	
	var sontree = $("#parent_"+typeid);
	
	if(sontree.css("display")=='none'){
		sontree.css("display","");
		$("#row_type_"+typeid).removeClass("typeon");
		$("#row_type_"+typeid).addClass("typeoff");
	}else{
		sontree.css("display","none");
		$("#row_type_"+typeid).addClass("typeon");
		$("#row_type_"+typeid).removeClass("typeoff");
	}
	
}

function sec_group(_this){
	var typeid = $(_this).attr('typeid');	
	
	$("#area_list tr[parentid='"+typeid+"']").each(function(){
		if($(this).css("display")=='none'){
			$(this).css("display","");
			$("#row_type_sec_"+typeid).removeClass("typeon");
			$("#row_type_sec_"+typeid).addClass("typeoff");
			
		}else{
			$(this).css("display","none");
			$("#row_type_sec_"+typeid).addClass("typeon");
			$("#row_type_sec_"+typeid).removeClass("typeoff");
		}
	     
	});
	
	//alert($("#parent_10").find('tr').find('parentid').html());
	
}
</script>

<div id="dialog" title="系统提示" style="display:none"><p id="msg" style="text-align:center"></p></div>
</body>
</html>
